﻿using System;
using System.Collections.Generic;
using ProteinInsightInterface;
using System.Windows.Forms;
using System.Text;
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace ProteinInsightPlugin
{
    public class MyPlugin : MarshalByRefObject, IProteinInsightPlugin
    {
        public void Run(IProteinInsight pi)
        {
            try
            {
                //    write plug in code here.
                int maxNumColor = 0;
                for (int i = 0; i < pi.VPs.Count; i++)
                {
                    IVP vp = pi.VPs[i];
                    //if ( vp.DisplayStyle == IProteinInsight.IDisplayStyle.Surface && vp.PDB.IsBioUnitChild == true ||
                    //     vp.DisplayStyle == IProteinInsight.IDisplayStyle.Surface && vp.PDB.IsBioUnitParent == true )
                    if ( vp.PDB.IsBioUnitChild == true || vp.PDB.IsBioUnitParent == true)
                        maxNumColor ++;

                    pi.Utility.SetProgressInStatusBar((i+1) * 100 / pi.VPs.Count);
                }

                int iColor = 0;
                for ( int i = 0; i < pi.VPs.Count; i++ )
                {
                    IVP vp = pi.VPs[i];
                    //if ( vp.DisplayStyle == IProteinInsight.IDisplayStyle.Surface && vp.PDB.IsBioUnitChild == true ||
                    //     vp.DisplayStyle == IProteinInsight.IDisplayStyle.Surface && vp.PDB.IsBioUnitParent == true )
                    if ( vp.PDB.IsBioUnitChild == true || vp.PDB.IsBioUnitParent == true )
                    {
                        vp.Property.ColorScheme = IProperty.IColorScheme.SingleColor;
                        List<Color> colors = vp.Property.CustomizeColors;
                        colors[0] = pi.Utility.GetGradientColor(iColor ++, maxNumColor);
                        vp.Property.CustomizeColors = colors;
                    }
                    pi.Utility.SetProgressInStatusBar((i+1) * 100 / pi.VPs.Count);
                }
            }
            catch (Exception e)
            {
                pi.Utility.OutputMsg(e.ToString());
            }
        }

        public String Name
        {
            get
            {
                return "Set different color in biounit display";
            }
        }
    }
}

